Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

381
Visualizações
Is there a better way of writing variableName[0]?

Is there a better of writing const data = variableName[0]? I mean for variableName[0]. I do understand data is placed in index 0, but writing a number does not look professional ( to me atleast), So if there is some professional way someone knows, please share

To be more accurate, this is the case when the array has ONLY 1 element

almost 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You can try to use the array destructuring syntax:

const variableName = [1];
const data = variableName[0];
console.log(data);

const [data2] = variableName;
console.log(data2);

In above example it takes first array element and ignores the other ones. You can also destructure more than one element into named variables:

const [variable1, variable2] = yourArray;
almost 4 years ago · Santiago Trujillo Relatório

0

The following is the shortest syntax in the modern JavaScript:

const [data] = variableName;
almost 4 years ago · Santiago Trujillo Relatório

0

I would say that what looks potentially unprofessional is not so much writing a number, but rather storing data in an array like this. If your variable was an object {data: "someData"} instead of an array ["someData"] , then you could write

const {data} = variableName;

If you can't change the format, then there is nothing really wrong with variableName[0], but if you really want to avoid writing a number you could write

const [data] = variableName;

This may look a bit more cryptic to people not used to this syntax, though.

almost 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda